package com.lfd.controller;

import java.util.List;



import javax.naming.directory.InvalidSearchControlsException;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lfd.dto.AddCartDto;
import com.lfd.entity.Order;
import com.lfd.service.IOrderService;
import com.lfd.service.impl.IOrderServiceImpl;
import com.lfd.util.Result;
import com.lfd.util.UserUtil;
import com.lfd.vo.OrderVo;


@Controller
@RequestMapping("/order")
public class OrderController {
	private final Logger logger = Logger.getLogger(OrderController.class);
	@Autowired
	private IOrderService iOrderService;
	
    @ResponseBody
	@RequestMapping("/selectlist")
    public Result selectlist(Order order,@RequestParam(value  = "page",defaultValue = "1") Integer page, @RequestParam(value   = "limit",defaultValue = "10") Integer limit){
    System.out.println(order);
    	List<OrderVo> selectList = iOrderService.selectList(order, page, limit);
    	return new Result("0","",selectList.size(),selectList);
    	
}
  
    

    @ResponseBody
	@RequestMapping("/ids")
    public Result fh(@RequestParam ("ids")List<Long> ids, @RequestParam("orderstate")Long orderstate) {
        iOrderService.fh(ids, orderstate);
		return new Result("0","成功",100,null);
    	
    }
    
    @ResponseBody
	@RequestMapping("/add")
	public Result addOne(@RequestBody AddCartDto addCartDto){
    	    OrderVo orderVo =new OrderVo();
    	   
    	    orderVo.setOrderstatus(0);
    	   
    	    orderVo.setUserid(UserUtil.getId());
		try {
			
			iOrderService.add(orderVo, addCartDto.getCartProIds());
			
		} catch (Exception e) {
			
			logger.error("添加失败", e);
			
			return new Result("0","添加失败");
		}
		
		return new Result("0","添加成功");
		
	}

}
